package com.cbd.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cbd.dao.CbdpactDao;
import com.cbd.dao.CompanyDao;
import com.cbd.dao.CompanycarportDao;
import com.cbd.dao.CompanypactDao;
import com.cbd.dao.LandladyDao;
import com.cbd.dao.OperatorDao;
import com.cbd.dao.PersonalcarportDao;
import com.cbd.pojo.Cbdpact;
import com.cbd.pojo.Company;
import com.cbd.pojo.Companycarport;
import com.cbd.pojo.Companypact;
import com.cbd.pojo.Landlady;
import com.cbd.pojo.Operator;
import com.cbd.pojo.PageBean;
import com.cbd.pojo.PageBean;
import com.cbd.pojo.Personalcarport;
import com.cbd.service.OperatorService;
@Service
public class OperatorServiceImpl implements OperatorService {
	
	@Resource(name="cbdpactDaoImpl")
	private CbdpactDao cbdpactDao;
	@Resource(name="companycarportDaoImpl")
	private CompanycarportDao cartportDao;
	@Resource(name="companyDaoImpl")
	private CompanyDao companyDao;
	@Resource(name="operatorDaoImpl")
	private OperatorDao operatorDao;
	@Resource(name="companycarportDaoImpl")
	private CompanycarportDao companycarportDao;
	@Resource(name="companypactDaoImpl")
	private CompanypactDao companypactDao;
	@Resource(name="landladyDaoImpl")
	private LandladyDao landladyDao;
	@Resource(name="personalcarportDaoImpl")
	private PersonalcarportDao personalDao;
	@Override
	public int addCbdpact(Cbdpact cbdpact) {
		// TODO Auto-generated method stub
		return cbdpactDao.addCbdpact(cbdpact);
	}
	@Override
	public void addCompanyCarport(Companycarport carport) {
		// TODO Auto-generated method stub
		cartportDao.addCompanycarport(carport);
	}
	@Override
	public List<Company> getAllCompany() {
		// TODO Auto-generated method stub
		return companyDao.findAllCompany();
	}
	@Override
	public List<Object[]> showPIM(int id) {
		// TODO Auto-generated method stub
		
		return operatorDao.showPIM(id);
	}
	@Override
	public int updatePIM(String pwd, String tel,int id) {
		// TODO Auto-generated method stub
		int count=0;
		int cou=operatorDao.updatepwd(pwd,id);
		int cou1=operatorDao.updatetel(tel,id);
		if(cou==1||cou1==1){
			count=1;
		}
		return count;
	}
	@Override
	public int findCbdPactIDByNo(String pactNO) {
		// TODO Auto-generated method stub
		return cbdpactDao.getIDByPactNo(pactNO);
	}
	@Override
	public void addCompanyCarport(List<Companycarport> carportList) {
		for(Companycarport company:carportList){
			addCompanyCarport(company);
		}
		
		
	}
	@Override
	public List<Cbdpact> findAllCbdPactByCbdNo(String cbdNo) {
		// TODO Auto-generated method stub
		
		return cbdpactDao.findCompanypactByNO(cbdNo);
	}
	@Override
	public Operator findOperatorBuUserId(int userId) {
		// TODO Auto-generated method stub
		return operatorDao.findOperatorBuUserId(userId);
	}
	@Override
	public PageBean findAllOperator(PageBean pageBean) {
		// TODO Auto-generated method stub
		pageBean.setCountPage((int)Math.ceil((double)(operatorDao.getOperatorCount())/(double)(pageBean.getPageSize())));
		pageBean.setList(operatorDao.findAllOperator(pageBean));
		return pageBean;
	}
	@Override
	public Company getCompanyByID(int id) {
		// TODO Auto-generated method stub
		return companyDao.findCompanyById(id);
	}
	@Override
	public void canclePactByID(int parseInt) {
		cbdpactDao.canclePactByID(parseInt);
		
	}
	@Override
	public List<Companycarport> findAllCarPort() {
		// TODO Auto-generated method stub
		
		return companycarportDao.findAllCarPort();
	}
	@Override
	public void addCompanyPact(Companypact companyPact) {
		companypactDao.addCompanyPact(companyPact);
		
	}
	@Override
	public int findCompanyPactIDByNo(String pactNO) {
		// TODO Auto-generated method stub
		return companypactDao.findCompanypactIDByNO(pactNO);
	}
	@Override
	public void updateCompanyCarport(List<Companycarport> carportList) {
		// TODO Auto-generated method stub
		for(Companycarport companycarport : carportList){
			 companypactDao.updateCompanyCarport( companycarport);
		}
		
	}
	@Override
	public List<Companypact> findAllCompanyPactByPactNo(String trim) {
		// TODO Auto-generated method stub
		return companypactDao.findCompanypactByNO(trim);
	}
	@Override
	public void cancleCompPactByID(int parseInt) {
		// TODO Auto-generated method stub
		companypactDao.cancleCompPactByID(parseInt);
		companycarportDao.updateCarport(parseInt);
	}
	@Override
	public void updateCbdCompanyCarport(List<Companycarport> carportList) {
		// TODO Auto-generated method stub
		for(Companycarport companycarport : carportList){
			companycarportDao.updateCbdCompanyCarport(companycarport);
		}
	}
	@Override
	public List<Companycarport> findCompanyCarportByPactID(int parseInt) {
		// TODO Auto-generated method stub
		return companycarportDao.findCompanyCarportByPactID(parseInt);
	}
	@Override
	public int addOperator(Operator operator) {
		// TODO Auto-generated method stub
		return operatorDao.addOperatorDao(operator);
	}
	@Override
	public void updateLevelByOperatorId(List<Integer> level, int id) {
		// TODO Auto-generated method stub
		operatorDao.deleteLevelByOperatorId(id);
		operatorDao.saveLevelByOperatorId(level, id);
	}
	@Override
	public int deleteOperator(int operatorId) {
		// TODO Auto-generated method stub
		return operatorDao.deleteOperator(operatorId);
	}

	@Override
	public List<Landlady> findAllEnsureLandlady() {
		// TODO Auto-generated method stub
		boolean ladyType = false;
		return landladyDao.findAllLandladyByLadyType(ladyType);
	}
	@Override
	public List<Object[]> findOnePageEnsureLandlady(int pageSize, int currentPage) {
		// TODO Auto-generated method stub
		boolean ladyType = false;
		return landladyDao.findOnePageLandladyByLadyTypeAndPage(ladyType, pageSize, currentPage);
	}
	@Override
	public Landlady findLandladyByLadyID(int ladyID) {
		// TODO Auto-generated method stub
		return landladyDao.findLandladyByLadyID(ladyID);
	}
	@Override
	public int passLandladyRequest(int ladyID) {
		// TODO Auto-generated method stub
		boolean ladyType = true;
		return landladyDao.updateLandladyTypeByLadyID(ladyID, ladyType);
	}

	
	@Override
	public List<Landlady> findAllUnablePortByLadyID(int parseInt) {
		// TODO Auto-generated method stub
		return landladyDao.findAllUnablePortByLadyID(parseInt);
	}
	@Override
	public void accept(int parseInt) {
		personalDao.accept(parseInt);
		
	}
	@Override
	public PageBean findAllUnAbelPort(PageBean pageBean) {
		// TODO Auto-generated method stub
		
		return landladyDao.findAllUnAbelPort(pageBean);
	}
	@Override
	public PageBean findUnableProtByLadyID(PageBean pageBean, int parseInt) {
		// TODO Auto-generated method stub
		return personalDao.findUnableProtByLadyID(pageBean,parseInt);
	}

}
